/*
 * 类名称:ApplyOpenshopController.java
 * 包名称:com.platform.controller
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-09-05 00:19:55        lipengjun     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.annotation.SysLog;
import com.platform.entity.ApplyOpenshopEntity;
import com.platform.service.ApplyOpenshopService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 申请开店信息记录表Controller
 *
 * @author lipengjun
 * @date 2019-09-05 00:19:55
 */
@RestController
@RequestMapping("applyopenshop")
public class ApplyOpenshopController extends AbstractController {
    @Autowired
    private ApplyOpenshopService applyOpenshopService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("applyopenshop:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<ApplyOpenshopEntity> list = applyOpenshopService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询申请开店信息记录表
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("applyopenshop:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        query.put("isDelete", 0);
        List<ApplyOpenshopEntity> queryList= applyOpenshopService.queryList(query);
        int total = applyOpenshopService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(queryList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("applyopenshop:info")
    public R info(@PathVariable("id") Integer id) {
        ApplyOpenshopEntity applyOpenshop = applyOpenshopService.getById(id);

        return R.ok().put("applyopenshop", applyOpenshop);
    }

    /**
     * 新增申请开店信息记录表
     *
     * @param applyOpenshop applyOpenshop
     * @return R
     */
    @SysLog("新增申请开店信息记录表")
    @RequestMapping("/save")
    @RequiresPermissions("applyopenshop:save")
    public R save(@RequestBody @Validated ApplyOpenshopEntity applyOpenshop) {

        applyOpenshopService.add(applyOpenshop);

        return R.ok();
    }

    /**
     * 修改申请开店信息记录表
     *
     * @param applyOpenshop applyOpenshop
     * @return R
     */
    @SysLog("修改申请开店信息记录表")
    @RequestMapping("/update")
    @RequiresPermissions("applyopenshop:update")
    public R update(@RequestBody @Validated ApplyOpenshopEntity applyOpenshop) throws Exception {

        applyOpenshopService.update(applyOpenshop);

        return R.ok();
    }

    /**
     * 根据主键删除申请开店信息记录表
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除申请开店信息记录表")
    @RequestMapping("/delete")
    @RequiresPermissions("applyopenshop:delete")
    public R delete(@RequestBody Integer[] ids) {
        applyOpenshopService.deleteBatch(ids);

        return R.ok();
    }
}
